//
//  PublishedNewsFlashCell.m
//  Btpin
//
//  Created by Vic on 2019/12/17.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PublishedNewsFlashCell.h"

@interface PublishedNewsFlashCell ()
{
    UIView *bgView;
    UIImageView *timeIconImgView;
    UILabel *timeLbl;
    UILabel *titleLbl;
    UILabel *contentLbl;
    UILabel *statusLbl;
}
@end

@implementation PublishedNewsFlashCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    self.backgroundColor = COLOR_OF_CLEAR;
    self.contentView.backgroundColor = COLOR_OF_CLEAR;
    
    bgView = [UIToolsControl initViewWithFrame:CGRectMake(ScalePS(10), ScalePS(10), WIDTH-ScalePS(20), ScalePS(135)) backgroundColor:COLOR_OF_WHITE];
    bgView.layer.cornerRadius = ScalePS(8);
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    
    timeIconImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(ScalePS(15), ScalePS(20), ScalePS(15), ScalePS(15)) imageName:@"published_newsflash_time_icon"];
    [bgView addSubview:timeIconImgView];
    
    timeLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(timeIconImgView)+ScalePS(10), StartY(timeIconImgView), 200, ScalePS(15)) text:nil textColor:THEMECOLOR_OF_ORANGE font:Font_10];
    [bgView addSubview:timeLbl];
    
    titleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(ScalePS(15), EndY(timeIconImgView)+ScalePS(5), ViewWidth(bgView)-ScalePS(30), 20) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_15];
    titleLbl.numberOfLines = 0;
    titleLbl.lineBreakMode = NSLineBreakByWordWrapping;
    [bgView addSubview:titleLbl];
    
    contentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(ScalePS(15), EndY(titleLbl), ScalePS(260), ScalePS(30)) text:nil textColor:THEMECOLOR_OF_TEXT_9a9a9a font:Font_10];
    [bgView addSubview:contentLbl];
    
    statusLbl = [UIToolsControl initLabelWithFrame:CGRectMake(ViewWidth(bgView)-ScalePS(100), EndY(titleLbl), ScalePS(90), ScalePS(30)) text:nil textColor:THEMECOLOR_OF_TEXT_9a9a9a font:Font_12];
    statusLbl.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:statusLbl];
}
- (void)reloadDataForModel:(PublishedNewsFlashModel *)model {
    bgView.frame = CGRectMake(ScalePS(10), ScalePS(10), WIDTH-ScalePS(20), model.cellHeight-ScalePS(10));
    
    timeLbl.frame = CGRectMake(EndX(timeIconImgView)+ScalePS(10), StartY(timeIconImgView), 200, ScalePS(15));
    timeLbl.text = model.time;
    
    titleLbl.frame = CGRectMake(ScalePS(15), EndY(timeIconImgView)+ScalePS(5), ViewWidth(bgView)-ScalePS(30), model.titleHeight+ScalePS(20));
    titleLbl.text = model.title;
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = LineSpacingHeight;
    titleLbl.attributedText = [[NSAttributedString alloc] initWithString:model.title attributes:@{NSFontAttributeName:FontBold(Font_15), NSParagraphStyleAttributeName:paraStyle}];
    
    contentLbl.frame = CGRectMake(ScalePS(15), EndY(titleLbl), ViewWidth(bgView)-ScalePS(100), ScalePS(30));
    contentLbl.text = model.desc;
    
    statusLbl.frame = CGRectMake(ViewWidth(bgView)-ScalePS(100), EndY(titleLbl), ScalePS(90), ScalePS(30));
    // 审核状态 0-待审核 1-已通过 2-未通过
    if ([model.audit isEqualToString:@"0"]) {
        statusLbl.text = @"待审核";
        statusLbl.textColor = THEMECOLOR_OF_TEXT_9a9a9a;
    } else if ([model.audit isEqualToString:@"1"]) {
        statusLbl.text = @"已通过";
        statusLbl.textColor = THEMECOLOR_OF_GREEN;
    } else if ([model.audit isEqualToString:@"2"]) {
        statusLbl.text = @"未通过";
        statusLbl.textColor = THEMECOLOR_OF_RED;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
